cmake_minimum_required(VERSION 3.10)

project(toxdesk_static)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

add_compile_definitions(
    UNICODE)

if (MSVC)
    # warning level 4 and all warnings as errors
    add_compile_options(/W3 )
    add_compile_definitions(_CRT_SECURE_NO_WARNINGS
        NOMINMAX
        SODIUM_STATIC
        __STDC_CONSTANT_MACROSE)
else()
    add_compile_options(-Wall -Wextra -pedantic -fpermissive)
    add_definitions (-Wno-unused-parameter)
    add_definitions (-Wno-unused-variable)
    add_definitions (-Wno-unused-function)
endif()

include_directories(${CMAKE_CURRENT_SOURCE_DIR}
    ../../third_party/include
    ./audio/include
    ./audio/src
    ../../third_party/libvpx
     ../../third_party/c-toxcore
     ../../third_party/opus/include
    )

if (WIN32)
    include_directories(../../third_party/pthread4w)
    #link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/lib/x64)
elseif(ANDROID)
    #message("..............E:/toxdesk/third_party/lib/arm64-v8a")
    link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/lib/arm64-v8a/
        )
else()
    #message("..............${CMAKE_CURRENT_SOURCE_DIR}")
    link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/lib/linux64/)
endif()

if(WIN32)
    list(APPEND EXTRA_SOURCE
        platform/d3d_helper.cpp
        platform/system_error.cpp
        platform/system_lib.cpp
        platform/system_version.cpp
        video/record_desktop.cpp
        video/record_desktop_duplication.cpp
        video/record_desktop_gdi.cpp)
endif()
if(UNIX)
    list(APPEND EXTRA_SOURCE
        video/record_desktop.cpp
        video/record_desktop_x11.cpp)
endif()

set(SOURCE_FILE audio/src/audio.cpp
    audio/src/backend/alsink.cpp
    audio/src/backend/alsource.cpp
    audio/src/backend/openal.cpp
    core/contactid.cpp
    core/core.cpp
    core/coreav.cpp
    core/coreext.cpp
    core/corefile.cpp
    core/dhtserver.cpp
    core/toxcall.cpp
    core/toxencrypt.cpp
    core/toxfile.cpp
    core/toxid.cpp
    core/toxlogger.cpp
    core/toxoptions.cpp
    core/toxpk.cpp
    core/toxstring.cpp
    friendlist.cpp
    model/contact.cpp
    model/friend.cpp
    model/message.cpp
    model/status.cpp
    net/bootstrapnodeupdater.cpp
    ext/tox_extension_messages.c
    ext/toxext.c
    ToxDeskApp.cpp
    persistence/serialize.cpp
    persistence/settings.cpp

    util/sha256.cpp
    video/desktopsource.cpp
    video/corevideosource.cpp

    video/video.c
    video/videomode.cpp
    video/videosource.cpp
    keyevent/KeyMap.cpp
    keyevent/keysym2ucs.c
    keyevent/InputInjector.cpp
    ${EXTRA_SOURCE}
    )


set(CMAKE_VERBOSE_MAKEFILE on)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -o2")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")

#add_executable(ToxDesk ${SOURCE_FILE})


#SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../bin)       #设置可执行文件的输出目录

#SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../lib)           #设置库文件的输出目录


#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/bin)

#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR}/../bin)

#上面两条语句分别设置了Debug版本和Release版本可执行文件的输出目录,

#一旦设置上面的属性,在任何环境下生成的可执行文件都将直接放在你所设置的目录.

#set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/../lib)
#set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR}/../lib)




if(MSVC) # Check if we are using the Visual Studio compiler
    SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} /SUBSYSTEM:WINDOWS") # Tell the project how to behave in this environment
elseif(CMAKE_COMPILER_IS_GNUCXX)
    #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mwindows") # Tell the project how to behave in this environment
elseif(Clang)
    message(SEND_ERROR "You are using an unsupported Windows compiler! (Not MSVC or GCC)")
endif()
add_library(${PROJECT_NAME} STATIC ${SOURCE_FILE})


if(WIN32)
    target_link_libraries(${PROJECT_NAME}  PUBLIC
        ${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/lib/x64/toxcore.lib
        ${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/lib/x64/libsodium.lib
        ${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/lib/x64/vpxmd.lib
        ${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/lib/x64/opus.lib
        Strmiids.lib
        pthreadVC3.lib)
elseif(ANDROID)
    set(libpath ${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/lib/${CMAKE_ANDROID_ARCH_ABI})
    target_link_libraries(${PROJECT_NAME} PUBLIC
        ${libpath}/libsodium.a
        ${libpath}/libtoxcore.a
        ${libpath}/libvpx.a
        ${libpath}/libopus.a
        )
else()
    target_link_libraries(${PROJECT_NAME} PUBLIC
        ${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/lib/linux64/libtoxcore.a
        ${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/lib/linux64/libsodium.a
        ${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/lib/linux64/libvpx.a
        ${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/lib/linux64/libopus.a
        -lXext
        -lX11)
endif()

#if(WIN32)
#    target_link_libraries(${PROJECT_NAME} optimized
#        toxcore.lib
#        libsodium.lib
#        vpxmd.lib
#        opus.lib
#        Strmiids.lib
#        pthreadVC3.lib)
#endif()



